﻿/**
 *	html/pem_data_tunnel.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-08-11		create the file
 */

/**
 *	init tunnel
 */
function init_tunnel( )
{
    _create_tunnel_type();
    _create_tunnel();
}

/**
 *	create tunnel option type
 */
var g_tunnel_type;
function _create_tunnel_type()
{
    Ext.define
    ( "model_tunnel_type", {
         extend:"Ext.data.Model",
         fields:[
             {name:"serial",	type:"int"},
             {name:"type", 		type:"string"}
         ]
    });

    g_tunnel_type = new Ext.data.ArrayStore
    ({
         autoLoad:true,
         model:"model_tunnel_type",
         data:[[0, "全部"]]
    });
}

/**
 *	create the tunnel option store
 */
var g_tunnel;
var g_tunnel_combox;
function _create_tunnel()
{
    Ext.define
    ( "model_tunnel_option", {
         extend:"Ext.data.Model",
         fields:[
             {name:"serial",		type:"int"},
             {name:"name", 			type:"string"},
             {name:"type", 			type:"string"},		// the value in the tunnel_type
             {name:"number", 		type:"string"},
             {name:"host",			type:"string"},		// host id
             {name:"remark", 		type:"string"},
             {name:"used",			type:"int"}
         ],
         proxy:"memory"
    });

    g_tunnel = new Ext.data.ArrayStore
    ({
         autoLoad:true,
         model:"model_tunnel_option",
    });

    g_tunnel_combox = Ext.create
    ("Ext.data.ArrayStore",{
         autoload:true,
         model:"model_tunnel_option",
    })
}

/**
 *	update the tunnel record to data base
 *
 *	@values			[in] the record values get from the tunnel edit form
 */
function update_tunnel_record( values )
{
    var	name	= values["name"];
    var type	= values["type"];
    var number	= values["number"];
    var host	= values["host"];
    var remark	= values["remark"];
    var used	= values["used"];

    qt_html.update_tunnel( name, type, number, host, remark, used );
}

/**
 *	delete the tunnel record from data base
 *
 *	@record			[in] the record that need to be deleted
 */
function delete_tunnel_record( record )
{
    qt_html.delete_tunnel( record.get( "number" ) );
}

/**
 *	callback for setting tunnel type
 */
function callback_set_tunnel_type( serial, type )
{
    var		index = g_tunnel_type.count();

    g_tunnel_type.insert( index, [[serial, type]] );
}

/**
 *	callback for setting tunnel
 */
function callback_set_tunnel( serial, name, type, number, host, remark, used )
{
    var		index = g_tunnel.count();

    g_tunnel.insert( index, [[serial, name, type, number, host, remark, used]] );
}
